﻿// =================================================================== 
// 数据实体层(GDIT.Model)实体映射
//====================================================================
// 文件：Mtb_Users.cs
// 项目名称：学院网站
// 创建时间：2012-08-08
// 负责人：ChenZhiGang
// 引用DevExpress.Xpo程序集
// 程序集介绍：用户信息实体类
// ===================================================================
using DevExpress.Xpo;

namespace GDIT.Model
{

    public class Mtb_Users : PersistentClass
    {
        public Mtb_Users()
        : base()
    {
        this.Modified = false;
    }

        public Mtb_Users(Session theSession)
        : base(theSession)
    {
        this.Modified = false;
    }

    private string _userName = string.Empty;
    /// <summary>
    /// 用户名称
    /// </summary>
    [DbType("varchar(50)")]
    public string UserName
    {
        get { return _userName; }
        set
        {
            if (_userName != value)
            {
                _userName = value;
                if (!IsLoading) { this.Modified = true; }
            }
        }
    }

    private string _userPwd = string.Empty;
    /// <summary>
    /// 用户密码
    /// </summary>
    [DbType("varchar(50)")]
    public string UserPwd
    {
        get { return _userPwd; }
        set
        {
            if (_userPwd != value)
            {
                _userPwd = value;
                if (!IsLoading) { this.Modified = true; }
            }
        }
    }

    /// <summary>
    /// 用户所属角色
    /// </summary>
    [Association("RolesUsers")]
    public Mtb_Roles Role;

    /// <summary>
    /// 用户所属部门
    /// </summary>
    [Association("DepartmentUsers")]
    public Mtb_Department Department;

    /// <summary>
    /// 用户所发表的公告列表
    /// </summary>
    [Association("UserBulletinArticles", typeof(Mtb_BulletinArticle))]
    public XPCollection BulletinArticles
    { 
        get
        {
            return GetCollection("BulletinArticles"); 
        }
    }

    /// <summary>
    /// 用户所发表的校园资讯列表
    /// </summary>
    [Association("UserCollegeInformationArticles", typeof(Mtb_CollegeInformationArticle))]
    public XPCollection CollegeInformationArticles
    {
        get
        {
            return GetCollection("CollegeInformationArticles");
        }
    }


    /// <summary>
    /// 防止编辑后马上保存
    /// </summary>
    protected override void EndEdit()
    {
        return;
    }

    /// <summary>
    /// 检验数据
    /// </summary>
    /// <returns></returns>
    public override string GetDataError()
    {
        if (this._userPwd.Trim().Length == 0) { return string.Format("用户密码不能为空"); }
        if (this._userName.Trim().Length == 0) { return string.Format("用户名不能为空"); }
        return "";
    }
    }

}